let router=require('koa-router')();
let {accessToken}=require('./../config')
let {checkExist}=require('./../util')
let service=require('./../service/methods')
Object.keys(service).forEach(funcName=>{
    router.get(`/api/${funcName}`,function (ctx) {
        if(!checkExist(ctx.query,'accessToken',accessToken)){ctx.body=`{message:"缺少参数accessToken"}`;return }
        ctx.body= service[funcName](ctx.query)
        return;
    })
    router.post(`/api/${funcName}`,function (ctx) {
        if(!checkExist(ctx.body,'accessToken',accessToken)){ctx.body=`{message:"缺少参数accessToken"}`;return }
        ctx.body=service[funcName](ctx.body);
        return;
    })
})
router.get('/login',function (ctx) {
    ctx.body=service.login()
})
module.exports = router;